package cn.edu.fudan.bdke.ncov.qa.dao;

import org.neo4j.driver.Record;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xym
 * @since 1.0
 */
public class Neo4jGraphDao {
    /**
     * 根据给定的cypher语句在图数据库中查询
     *
     * @param cypher cypher查询语句
     * @return 结果用保存为字符串形式
     */
    public List<String> execute(String cypher) {
        List<String> returnResults = new ArrayList<>();
        Session session = GraphDbSession.getSession();
        Result dbResult = session.run(cypher);
        while (dbResult.hasNext()) {
            Record record = dbResult.next();
            String name = record.get("t").asNode().get("name").toString();
            returnResults.add(name);
        }
        return returnResults;
    }
}
